package com.eascs.web.demo.view;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.view.ViewContext;
import com.eascs.web.demo.form.SubmitDateForm;

@Controller
@RequestMapping(value = "/master")
public class SampleMasterViewController extends DefaultMasterViewController {
	private final Logger logger = LoggerFactory.getLogger(SampleMasterViewController.class);

	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String index() {
		logger.debug("SampleMasterViewController.index(..)");
		ViewContext.put("k1", "v1");
		ViewContext.put("title", "master");
		return "master";
	}

	@RequestMapping(value = "/form-submit", method = RequestMethod.GET)
	public String formSubmit(SubmitDateForm submitDateForm) {
		logger.debug("SampleMasterViewController.formSubmit(..)");
		ViewContext.put("id", submitDateForm.getId());
		ViewContext.put("password", submitDateForm.getPassword());
		return "formSample";
	}

	@RequestMapping(value = "/to-baidu", method = RequestMethod.GET)
	public String redirectToBaidu(SubmitDateForm submitDateForm) {
		throw new com.eascs.web.exception.RedirectException("http://www.baidu.com");
	}

	@RequestMapping(value = "/to-form-submit", method = RequestMethod.GET)
	public String redirectToHome(SubmitDateForm submitDateForm) {
		throw new com.eascs.web.exception.RedirectException("/master/form-submit");
	}

	@Override
	public void preHandle() {
		ViewContext.put("k2", "v2");
		logger.debug("SampleMasterViewController.preHandle(..)");
	}

	@Override
	public void afterCompletion() {
		ViewContext.put("k3", "v3");
		logger.debug("SampleMasterViewController.afterCompletion(..)");
	}

}
